﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using WyUnity.Utility.ExtentionMethods;

namespace WyUnity.Utility
{
    public class Logger
    {
        public Logger(string name)
        {
            _log = LogManager.GetLogger(name);
        }
        public Logger(Type type)
        {
            _log = LogManager.GetLogger(type);
        }
        private readonly ILog _log;

        public void Info(object obj)
        {
            if (_log.IsInfoEnabled)
            {
                _log.Info(obj.SerializeToXml());
            }
        }

        public void Info(string msg)
        {
            if (_log.IsInfoEnabled)
                _log.Info(msg);
        }

        public void Info(string msg, params object[] pam)
        {
            if (_log.IsInfoEnabled)
                _log.InfoFormat(msg, pam);
        }
        public void Error(string msg, params object[] pam)
        {
            if (_log.IsErrorEnabled)
                _log.ErrorFormat(msg, pam);
        }
        public void Error(string msg, Exception er)
        {
            if (_log.IsErrorEnabled)
                _log.Error(msg, er);
        }

        public void Debug(object obj)
        {
            if (_log.IsDebugEnabled)
            {
                _log.Debug(obj.SerializeToXml());
            }
        }

        public void Debug(string msg, Exception er)
        {
            if (_log.IsDebugEnabled)
                _log.Debug(msg, er);
        }

        public void Debug(string msg)
        {
            if (_log.IsDebugEnabled)
                _log.Debug(msg);
        }

        public void Debug(string msg, params object[] pam)
        {
            if (_log.IsDebugEnabled)
                _log.DebugFormat(msg, pam);
        }

        public void Warn(string msg)
        {
            if (_log.IsWarnEnabled) _log.Warn(msg);
        }
    }
}
